/**
* 	\file  cant.h
*
*  	\brief Driver interface to Vector CAN-Cards.
*
*  	\author Michael J. Hohmann <michael.hohmann@linde-mh.de>
*
*    The module cant.c provide an interface to access CAN-Card from Vector.
*
*
*/

#ifndef CANT_H_INCLUDED
#define CANT_H_INCLUDED

#ifdef __cplusplus
  extern "C" {
#endif

/*===========================[ public includes   ]============================*/
#include "../cfg/prj.h"

#include <windows.h>
#include "vxlapi.h"
#include "../canmsg/canmsg.h"
/*===========================[ public defines    ]============================*/
/** Number of possible IDs */
#define CANT_ID_TABLE_SIZE  U16_CONST(0x800)

/*===========================[ public datatypes  ]============================*/

struct cant_obj;/* forward declaration */

/** Callback function Type */
typedef void (*cant_rx_callback_function_t)(struct cant_obj * me, struct canmsg* msg, void* data);

/** Data stored for each install callback function.
 * \note It is not expected to use this struct definition outside of this module.
 * \see cant_install_rx_callback()
 */
struct cant_rx_callback
{
   cant_rx_callback_function_t function;
   void *data;
};

/** CANT Object definition. */
struct cant_obj
{
   XLaccess       xlChannelMask;                   /**< Global channel mask (includes all founded channels)     */
   XLaccess       xlPermissionMask;                /**< Global permission mask (includes all founded channels)  */
   XLportHandle   xlPortHandle;                    /**< Global port handle (we use only one!)                   */
   unsigned int   BaudRate;                        /**< Default baud rate                                       */
   XLaccess       xlChanMaskTx;                    /**< Channel Mask. Indicate used channel.                   */
   XLhandle       hMsgEvent;                       /**< notification handle for the receive queue              */
   HANDLE         hRXThread;                       /**< thread handle (RX)                                     */
   int            RXThreadRun;                     /**< flag to start/stop the RX thread                       */
   struct cant_rx_callback rx_dispatcher[CANT_ID_TABLE_SIZE];   /**< Store callback function for all IDs                     */
   struct cant_rx_callback rx_default_callback;    /**< Store default callback                                 */
   U32            serial_number;                   /**< Serial number of the hardware interface that is used   */
   int            channel_index;                   /**< Index of the hardware channel that is used             */
};

/*===========================[ public variables  ]============================*/

/*===========================[ public functions  ]============================*/
struct cant_obj * cant_create(unsigned int BaudRate,CH *name, U16 logic_channel );
RC cant_construct(struct cant_obj* me, unsigned int BaudRate,CH *name, U16 channel );
RC cant_install_default_rx_callback( struct cant_obj* me, cant_rx_callback_function_t callback, void * data );
RC cant_install_rx_callback( struct cant_obj* me, unsigned int id, cant_rx_callback_function_t callback, void * data );
RC cant_tx(struct cant_obj *me, struct canmsg *msg);
RC cant_activate(struct cant_obj* me, BO value);
RC cant_close(struct cant_obj *me);
RC cant_flushQueues(struct cant_obj* me);
RC cant_destroy(struct cant_obj *me);

/*============================================================================*/

#ifdef __cplusplus
  }
#endif

#endif  /* CANT_H_INCLUDED */

/*******************************************************************************
*        Copyright 2006-2018 Linde Material Handling. All rights reserved.     *
*******************************************************************************/




























